#include "..\..\NahidaProject-UnitTest\Sources\NahidaUnitTest.h"

#include "..\Sources\BloomFilter.h"
#include "..\Sources\HTTPRequest.h"
#include "..\Sources\Logger.h"
#include "..\Sources\SortModule.h"

TESTCASE(BloomFilterTest) {
	NahidaProject::BloomFilter<100> bloomFilter;

	bloomFilter.Set("Object A");
	bloomFilter.Set("Object B");
	bloomFilter.Set("Object C");

	JUDGE_EQUAL(bloomFilter.Test("Object A"), 1);
	JUDGE_EQUAL(bloomFilter.Test("Object B"), 1);
	JUDGE_EQUAL(bloomFilter.Test("Object C"), 1);
	JUDGE_EQUAL(bloomFilter.Test("Object D"), 0);

	JUDGE_EQUAL(bloomFilter.EstimateElementCount(), 3);

	std::cout << "Used bits: " << bloomFilter.GetUsedBits() << std::endl;
	std::cout << "Load factor: " << bloomFilter.LoadFactor() << std::endl;
	std::cout << "False positive rate: " << bloomFilter.EstimateFalsePositiveRate(3) << std::endl;
	bloomFilter.Clear();
	JUDGE_EQUAL(bloomFilter.GetUsedBits(), 0);
}

TESTCASE(HTTPRequestTest) {
	NahidaProject::HTTPRequest::AsyncHTTPRequest request;
	request.SetHeader("Authorization", "Bearer 123");
	request.SetHeader("User-Agent", "HTTPRequest/1.0");

	request.Post("http://postman-echo.com/post", [](const std::string& response) {
		std::cout << "Echo post:\n\n" << response << "\n\n";
	}, NahidaProject::HTTPRequest::ContentType::json, R"({"name": "olli", "job": "pro coder"})");

	while (!request.Server()) {
		
	 }

	request.Get("http://postman-echo.com/get", [](const std::string& response) {
		std::cout << response;
	});
	

	while (!request.Server()) {

	 }
	std::cout << "" << std::endl;
}

TESTCASE(LoggerTest) {
	NahidaProject::Logger::GetInstance()->Open("TestRead.log");
	NahidaProject::Logger::GetInstance()->SetMax(1024);

	Debug("This is a debug imformation");
	Information("This is a imformation imformation");
	Warning("This is a %s imformation", "warning");
	Error("This is a error imformation");
	// FATAL("Hello NahidaProject"); Will be stop and return -1
}

TESTCASE(SortModuleTest) {
	std::vector<int> a = { 5, 6, 7, 2, 1, 4, 3 };
	std::vector<int> b = { 1, 2, 3, 4, 5, 6, 7 };

	JUDGE_EQUAL(NahidaProject::SortModule::BubbleSort(a), b);
	JUDGE_EQUAL(NahidaProject::SortModule::InsertSort(a), b);
	JUDGE_EQUAL(NahidaProject::SortModule::SelectSort(a), b);
}


int main() {
	NahidaProject::NahidaUnitTest::RunAllTests();
	return 0;
}